package com.train.mgr.modules.biz.controller;

import com.train.mgr.modules.biz.dto.request.LessonRoleReqDTO;
import com.train.mgr.modules.system.dto.request.groups.Insert;
import com.train.mgr.modules.system.dto.request.groups.Update;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import com.train.mgr.modules.biz.entity.LessonRole;
import com.train.mgr.modules.biz.service.*;

import com.train.common.model.PageResult;
import com.train.common.model.R;
import com.train.common.model.PageParam;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * 课时角色表 前端控制器
 * @author cxg
 * @date 2025-09-30
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@Api( tags = "角色管理[企业端]")
@RequestMapping("/lessonRole")
public class LessonRoleController {

    private final ILessonRoleService lessonRoleService;

    /**
     * 功能描述:单个获取 (仅作参考)
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("查询详情")
    public R<LessonRole> getById(@PathVariable(name = "id") Long id) {
        LessonRole lessonRole = lessonRoleService.getById(id);
        return R.succeed(lessonRole);
    }


    /**
     * 条件 分页查询 (仅作参考)
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/page")
    @ApiOperation("角色列表")
    public R<PageResult<LessonRole>> page(PageParam params) {
        PageResult<LessonRole> iPage =lessonRoleService.page(params);
        return R.succeed(iPage);
    }

    /**
	 * 新增
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/add")
    @ApiOperation("新增角色")
    public R<Boolean> add(@RequestBody @Validated(Insert.class) LessonRoleReqDTO body) {
        Boolean result = lessonRoleService.add(body);
        return R.succeed(result);
    }

	/**
	 * 更新
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/update")
    @ApiOperation("更新角色")
    public R<Boolean> update(@RequestBody @Validated(Update.class) LessonRoleReqDTO body) {
        Boolean result = lessonRoleService.update(body);
        return R.succeed(result);
    }

}
